<template>
	<view class="content">
		<view class="line"><navigator style="font-weight: bold;" url="/pages/gcedit">添加工程</navigator></view>
		<view class="line" v-for="(item,index) in gclist" v-bind:key="item.id">
			<view class="txt"><navigator @click="look(item.id)" :url="'/pages/gcdetail?id='+item.id" open-type="switchTab">{{item.names||'--'}}</navigator></view> 
			<navigator @click="look(item.id)" :url="'/pages/gcdetail?id='+item.id" open-type="switchTab">明细</navigator> 
			<navigator :url="'/pages/gcedit?id='+item.id">编辑</navigator>
			<button @click="gcdel(item.id)">删除</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				gclist: [] //工程列表
			}
		},
		onShow(){
			this.loadgc();
		},
		onLoad() {
			this.loadgc();
		},
		methods: {
			loadgc(){
				let self = this;
				uni.request({
					url:this.apibase + "gclist",
					success: (res) => {
						self.gclist = res.data;
						//console.log(res.data);
					}
				});
			},
			look(id){
				uni.setStorage({
					data:id,
					key:"gcid"
				})
				//console.log("look",id);
			},
			goto(url){
				uni.navigateTo({
					url:url,
				})
			},
			gcdel(id){
				let self = this;
				uni.request({
					url:this.apibase + "gcdel?id=" + id,
					success: (res) => {
						self.loadgc();
					}
				});
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.txt{
		width: 60%;
		padding-left:10rpx;
	}
</style>
